package com.shycloud.mido.member.controller;

import com.shycloud.mido.common.core.util.R;
import com.shycloud.mido.common.pay.alipay.bean.AliReturnPayBean;
import com.shycloud.mido.member.api.dto.MemberRoleDTO;
import com.shycloud.mido.member.api.entity.*;
import com.shycloud.mido.member.api.util.Constant;
import com.shycloud.mido.member.api.vo.PayVO;
import com.shycloud.mido.member.api.vo.RoleVO;
import com.shycloud.mido.member.service.*;
import com.shycloud.mido.member.api.enums.MessageCodeEnum;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author yyy
 * @date 2019/05/20
 * <p>
 * 会员角色权限手机接口
 */
@RestController
@AllArgsConstructor
@RequestMapping("/v1/mobile")
@Api(value = "mobile", description = "会员角色权限手机接口")
@ApiIgnore
public class MobileRoleController {

	private MemberRoleService memberRoleService;
	private MemberService memberService;
	private MemberPriceService memberPriceService;
	//private MemberOrderService memberOrderService;
	private MemberPriceIosService memberPriceIosService;

	/**
	 * 会员角色
	 *
	 * @param memberId 会员ID
	 * @return R
	 */
	@PostMapping("/memberRole")
	public R memberRole(String memberId) {
		RoleVO vo = new RoleVO();
		//查询会员角色
		List<MemberRole> role = memberRoleService.getRole(memberId);
		for (int i = 0; i < role.size(); i++) {
			if (role.get(i).getRoleCode().equals(Constant.VIP_MEMBER)) {
				vo.setRegular(true);
			} else if (role.get(i).getRoleCode().equals(Constant.VIP_MEMBER)) {
				vo.setSenior(true);
			}
		}
		//会员信息——纠错大师
		//Master master = masterService.getByMemberId(memberId);
		//if (null != master) {
			//vo.setErrorCorrection(true);
		//}
		//会员信息-机构教师
		Member member = memberService.getById(memberId);
		if (Constant.ORGAN_TEACHER.equals(member.getIsOrganTeacher())) {
			vo.setRegular(true);
			//vo.setInstitutional(true);
		}
//		//平台认证教师
//		if(Constant.ORGAN_TEACHER.equals(member.getIsTeacher())){
//			vo.setPlatform(true);
//		}
//		Teacher teacher =teacherService.getByMemberId(memberId);
//		if(null!=teacher){
//			vo.setPlatform(true);
//		}
		return new R<>(vo, MessageCodeEnum.SUCCESS.getMessage());
	}

	/**
	 * 获取会员价格列表
	 *
	 * @param phone 会员类型
	 * @param type  会员类型
	 * @return
	 */
	@PostMapping("/selMemberPrice/{phone}")
	public R selMemberPrice(@PathVariable("phone") String phone, String type) {
		if (Constant.IOS_PRICE.equals(phone)) {
			List<MemberPriceIos> list = memberPriceIosService.selIosMemberPrice(type);
			return new R<>(list, MessageCodeEnum.SUCCESS.getMessage());
		} else {
			List<MemberPrice> list = memberPriceService.selMemberPrice(type);
			return new R<>(list, MessageCodeEnum.SUCCESS.getMessage());
		}

	}

	/**
	 * 离会员到期1个月
	 * 离会员到期7天
	 * 离会员到期3天
	 * de 所有会员
	 *
	 * @return
	 */
	@PostMapping("/roleExpire")
	public List<MemberRoleDTO> roleExpire() {
		return memberRoleService.roleExpire();
	}
}
